/*
 * Copyright 2009 André Luiz Alves Moraes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * */

package org.alamoraes.cmdutils.parser;

/**
 *
 * @author andre
 */
public class CommandLineParameter {
    private String paramName;
    private boolean required;
    private String description;
    private String value;
    private boolean requiredValue;
    private boolean hasValue;

    public CommandLineParameter() {
    }

    public CommandLineParameter(String paramName, boolean required, String description, String value, boolean requiredValue, boolean hasValue) {
        this.paramName = paramName;
        this.required = required;
        this.description = description;
        this.value = value;
        this.requiredValue = requiredValue;
        this.hasValue = hasValue;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getParamName() {
        return paramName;
    }

    public void setParamName(String paramName) {
        this.paramName = paramName;
    }

    public boolean isRequired() {
        return required;
    }

    public void setRequired(boolean required) {
        this.required = required;
    }

    public boolean isRequiredValue() {
        return requiredValue;
    }

    public void setRequiredValue(boolean requiredValue) {
        this.requiredValue = requiredValue;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public boolean isHasValue() {
        return hasValue;
    }

    public void setHasValue(boolean hasValue) {
        this.hasValue = hasValue;
    }

    public boolean isSet() {
        return getValue() != null && !"".equals(getValue());
    }

    public void markAsSet() {
        setValue("true");
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (!isRequired()) sb.append("[");
        sb.append("--" + getParamName());
        if (!isRequired()) sb.append("]");
        if (isHasValue()) {
            sb.append("  " + "<value>");
        }
        sb.append("");
        return StringFormatting.padRight(sb.toString(), 25, true) + ">" + getDescription();
    }
}
